home *** CD-ROM | disk | FTP | other *** search
/ Ian & Stuart's Australian Mac 1 / Ian and Stuart's One (Australia).iso / Australasian Legends / Commercial / Rainbow Hill / MacDOS™ 2.0.0 / batches / movefile.bat < prev    next >
DOS Batch File  |  1994-06-30  |  2KB  |  65 lines

  1. @echo off
  2. !  movefile.bat    Batch file to move a file
  3. !
  4. !  movefile name [dest]
  5. !
  6. !  where 'name' is the file to be moved and 'dest' is the path of the
  7. !  destination folder. 'name' can be preceded by a path and a volume ID.
  8. !  If 'dest' is missing, the current directory is used as destination.
  9. !
  10. !  movefile.bat calls extractName and uniqueTempName
  11. !
  12. !  Copyright © 1994 by Rainbow Hill Pty Ltd. All rights reserved.
  13. !
  14.  
  15.     ! ensure that the first parameter is there and that the third one is not
  16.     set doserr=13
  17.     if not "%3 " == " " goto ERR_LBL
  18.     if "%1 " == " " goto ERR_LBL
  19.  
  20.     ! ensure that the requested file is there
  21.     set doserr=27
  22.     if not exist "%1" goto ERR_LBL
  23.  
  24.     ! determine the destination folder
  25.     set movefile_folder=%WHERE%
  26.     if "%2 " == " " goto FOLDER_OK_LBL
  27.     if not existdir "%2" goto ERR_LBL
  28.     set movefile_folder=%2
  29. :FOLDER_OK_LBL
  30.  
  31.     ! copy the file
  32.     set doserr=0
  33.     onerror ERR_LBL
  34.     call extractName "%1" movefile_name
  35.     if not %doserr% == 0 goto ERR_LBL
  36.     copy "%1" "%movefile_folder%\%movefile_name%"
  37.  
  38.     ! Remove the source but only if it does not coincide with the destination. There
  39.     ! could be aliased folders in the paths. Therefore, we cannot simply compare the
  40.     ! two path strings. We have to rename the destination, delete the source
  41.     ! (which we might fail to find), and finally revert the name of the destination
  42.     ! to what it was before the first renaming.
  43.  
  44.     ! get a unique file name and rename the destination
  45.     call uniqueTempName movefile_temp "%movefile_folder%"
  46.     ren "%movefile_folder%\%movefile_name%" "%movefile_temp%"
  47.  
  48.     ! delete the source and re-rename the destination
  49.     onerror SKIP_LBL
  50.     del "%1"
  51. :SKIP_LBL
  52.     onerror ERR_LBL
  53.     ren "%movefile_folder%\%movefile_temp%" "%movefile_name%"
  54.     set doserr=0
  55.     goto DONE_LBL
  56.  
  57. :ERR_LBL
  58.     show %doserr%
  59.  
  60. :DONE_LBL
  61.     ! remove the global variables
  62.     set movefile_name=
  63.     set movefile_temp=
  64.     set movefile_folder=
  65.